home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 390 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: strauss.udel.edu!not-for-mail
  2. From: jcorig@strauss.udel.edu (John Pat Corigliano)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Is this a SAS/C bug or have I coded it wrong?
  5. Date: 7 Jan 1996 01:07:05 -0500
  6. Organization: University of Delaware
  7. Message-ID: <4cnnu9$eua@strauss.udel.edu>
  8. References: <4cfrc5$gsc@misery.millcomm.com> <4cm9kc$kf7@news.isc.rit.edu>
  9. NNTP-Posting-Host: strauss.udel.edu
  10.  
  11. In article <4cm9kc$kf7@news.isc.rit.edu>,  <mjp3783@alpha.isc.rit.edu> wrote:
  12. >In article <4cfrc5$gsc@misery.millcomm.com>, llucius@millcomm.com (Yambo) writes:
  13. >>   test( void )
  14. >>   {
  15. >>
  16. >>      if ( tmpbuf[0] & 0x1f == 1 )
  17. >>         return 1;
  18. >>
  19. >>      return 0;
  20. >>   }
  21. >
  22. >No, this is not a bug, this is optimization. If I type:
  23. >if (1==2) a(); else b();
  24. >
  25. >isn't that, really, the same as
  26. >b();
  27. >???
  28.  
  29. Well, you could at least tell him why ;)  It is a precedence problem.
  30. The == operator has a higher precedence than the & operator, so the
  31. code really is this:
  32.  
  33.       if (tmpbuf[0] & (0x1f == 1))
  34.  
  35. Since 0x1f != 1, this conditional is always equal to 0 (FALSE).  Therefore,
  36. SAS sees the code as:
  37.  
  38.      if (tmpbuf[0] & 0)
  39.  
  40. Since any number AND 0 will be 0, the statement really is:
  41.  
  42.      if (0) return 1;
  43.      else return 0;
  44.  
  45. And this is why the asm code sets D0 to 0 and returns.
  46. -- 
  47. John Corigliano                                  jcorig@strauss.udel.edu
  48. Computer and Information Science                  University of Delaware
  49. --
  50. "Never drive a car when your dead."  - Tom Waits
  51.